global M;
global ERROR_TOL;
global EPOCHS;
global UPPER_BOUND;
global LOWER_BOUND;
constants;

patterns = generatePatterns(M);             % Genero los patrones
solutions = generateSolutions(patterns);    % Genero el vector de salidas deseadas
vectorWeights = generateWeights();                % Genero las matrices con los pesos peque??os aleatorios

wf = trainNeuralNetwork (patterns, vectorWeights, solutions, ERROR_TOL, EPOCHS);

%for i = 1:length(solutions(1,:))
%    disp('Pattern: ');
%    disp(patterns(:,i)');
%    output = valPattern(wf, patterns(:,i));
%    disp('Output: ');
%    disp(output);
%    disp('Error:')
%    disp(abs(output - zFunction(patterns(:, i))));
%end

h = (UPPER_BOUND - LOWER_BOUND)/100;

[x, y] = meshgrid(LOWER_BOUND:h:UPPER_BOUND, LOWER_BOUND:h:UPPER_BOUND);

z = zeros(length(x(:,1)), length(x(1,:)));

for i=1:length(x(:,1))
    for j=1:length(x(1,:))
        z(i, j) = valPattern(wf, [x(i, j) ; y(i, j)]);
    end
end

surf(x, y, z);

disp('TERMINATED');
